<template>
  <div v-loading="loadings" class="app-container">
    <!-- 流水单信息 -->
    <h5 class="titleInfo">流水单信息</h5>
    <el-form ref="list" :inline="true" :model="list" label-width="130px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="流水单号">
            <span class="spanToInput">{{ list.orderSn | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="预约单号">
            <span class="spanToInput">{{ list.preOrderSn | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="流水单类型">
            <span class="spanToInput">{{ list.type | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="预约医院">
            <span class="spanToInput">
              {{ list.hospitalName | filterNull }}
            </span>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="list.formTypeValue">
          <el-form-item
            label="单数"
            v-if="list.formTypeValue.indexOf('传统') == -1"
          >
            <span class="spanToInput">
              {{ list.num == 0 ? "首单" : list.num }}
            </span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="创建日期">
            <span class="spanToInput">{{ list.createdAt | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="报单类型">
            <span class="spanToInput" v-if="list.formTypeValue">
              {{ list.formTypeValue }}
            </span>
          </el-form-item>
        </el-col>
        <!-- 新加字段 -->
        <el-col :span="8">
          <el-form-item label="活动名称">{{ list.salesTypeValue }}</el-form-item>
        </el-col>
        <!-- <el-col :span="8">
                    <el-form-item label="付款方式">{{ list.payment }}</el-form-item>
        </el-col>-->
      </el-row>
    </el-form>
    <!-- 人员信息 -->
    <div class="divBar" />
    <h5 class="titleInfo">人员信息</h5>
    <el-form ref="list" :inline="true" :model="list" label-width="130px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="客户姓名">
            <span class="spanToInput">{{ list.userName | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="客户手机号">
            <span class="spanToInput">{{ list.userPhone | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="推荐人姓名">
            <span class="spanToInput">{{ list.serviceName | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="推荐人手机号">
            <span class="spanToInput">
              {{ list.servicePhone | filterNull }}
            </span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="团队姓名">
            <span class="spanToInput">
              {{ list.teamUserName | filterNull }}
            </span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="团队手机号">
            <span class="spanToInput">
              {{ list.teamUserPhone | filterNull }}
            </span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="管家姓名">
            <span class="spanToInput">
              {{ list.butlerRealname | filterNull }}
            </span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="管家手机号">
            <span class="spanToInput">
              {{ list.butlerUsername | filterNull }}
            </span>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- 支付信息 -->
    <div class="divBar" />
    <h5 class="titleInfo">
      支付信息
      <b style="color: #999;font-size: 12px;"
        >注：线上收款/金银币金额不允许调高，只允许调低，现金/分期可调高或调低</b
      >
    </h5>
    <el-form v-if="list.paymentId == 4" ref="list" :inline="true" :model="list" label-width="130px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="消费总金额">
            <span class="spanToInput">{{ list.totalPrice | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="list.formTypeValue">
          <!-- <el-form-item label="实付扣除杂费金额" v-if="list.formTypeValue.indexOf('传统')==-1">
            <span class="spanToInput">{{ list.allPrice | filterNull }}</span>
          </el-form-item>-->
          <el-form-item label="实付扣除杂费">
            <span class="spanToInput">{{ list.allPrice }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="杂费金额">
            <span class="spanToInput">{{ idatas.toFixed(2) }}</span>
          </el-form-item>
        </el-col>
        <!-- <el-row>
          <el-col :span="24" style="text-align: right;">
            <el-button
              v-if="$route.name !='runWaterManageInfo'"
              style="margin-top:30px;margin-left:130px"
              type="primary"
              @click="submitFn('form')"
            >计算</el-button>
          </el-col>
        </el-row>-->
        <el-col :span="24">
          <el-table
            :data="list.flowList"
            border
            class="tableData"
            :summary-method="getSummaries"
            show-summary
            style="width: 100%; margin-top: 20px"
          >
            <el-table-column prop="id" label="付款方式">
              <span slot-scope="scope">
                <span v-if="scope.row.payType == 1">线上收款</span>
                <span v-if="scope.row.payType == 2">现金</span>
                <span v-if="scope.row.payType == 3">分期</span>
                <span v-if="scope.row.payType == 4">金币</span>
              </span>
            </el-table-column>
            <el-table-column prop="xfzMoney" label="消费总金额">
              <span slot-scope="scope">
                <el-input
                  v-model="scope.row.xfzMoney"
                  :disabled="!(ischeck === 3 && scope.row.payType == istype)"
                  type="text"
                  @change="abc(scope.row)"
                />
              </span>
            </el-table-column>
            <el-table-column prop="zlzMoney" label="扣除杂费金额">
              <span slot-scope="scope">
                <span v-if="scope.row.payType == 4"></span>
                <el-input
                  v-else
                  v-model="scope.row.zlzMoney"
                  :disabled="!(ischeck === 3 && scope.row.payType == istype)"
                  type="text"
                  @change="abc(scope.row)"
                />
              </span>
            </el-table-column>
            <el-table-column prop="zfMoney" label="杂费金额" />
            <el-table-column prop="payMoney" label="已支付总金额">
              <span slot-scope="scope">
                <el-input
                  v-model="scope.row.payMoney"
                  :disabled="!(ischeck === 1 && scope.row.payType == istype)"
                  type="text"
                  @change="abc(scope.row)"
                />
              </span>
            </el-table-column>
            <el-table-column prop="jlPayAccounts" label="已支付扣除杂费">
              <span slot-scope="scope">
                <el-input
                  v-model="scope.row.jlPayAccounts"
                  :disabled="!(ischeck === 1 && scope.row.payType == istype)"
                  type="text"
                  @change="abc(scope.row)"
                />
              </span>
            </el-table-column>

            <el-table-column prop="unpaidAccounts" label="未支付总金额">
              <span slot-scope="scope">
                <el-input
                  v-model="scope.row.unpaidAccounts"
                  :disabled="!(ischeck === 2 && scope.row.payType == istype)"
                  type="text"
                  @change="abc(scope.row)"
                />
              </span>
            </el-table-column>
            <el-table-column prop="jlUnpaidAccounts" label="未支付扣除杂费">
              <span slot-scope="scope">
                <el-input
                  v-model="scope.row.jlUnpaidAccounts"
                  :disabled="!(ischeck === 2 && scope.row.payType == istype)"
                  type="text"
                  @change="abc(scope.row)"
                />
              </span>
            </el-table-column>
            <el-table-column v-if="$route.name != 'runWaterManageInfo'" label="操作">
              <span slot-scope="scope">
                <el-button
                  v-if="scope.row.payType == 1"
                  type="text"
                  size="small"
                  @click="refundfun(1, scope.row.payType)"
                >调整已支付金额</el-button>
                <br />
                <el-button
                  v-if="scope.row.payType == 1"
                  type="text"
                  size="small"
                  @click="refundfun(2, scope.row.payType)"
                >调整未支付金额</el-button>
                <br />
                <el-button
                  v-if="scope.row.payType != 1"
                  type="text"
                  size="small"
                  @click="refundfun(3, scope.row.payType)"
                >调整金额</el-button>
              </span>
            </el-table-column>
          </el-table>
        </el-col>

        <!-- <el-col :span="12">
          <el-form-item label="现金补贴">
            <el-input v-model="list.cashAllowance"></el-input>
          </el-form-item>
        </el-col>-->
        <!-- <el-col :span="12">
          <el-form-item label="积分补贴">
            <el-input v-model="list.integralAllowance"></el-input>
          </el-form-item>
        </el-col>-->
        <el-col :span="12" style="margin-top:20px;">
          <el-form-item label="备注">
            <el-input v-model="list.userRemark" :disabled="$route.name == 'runWaterManageInfo'" />
          </el-form-item>
        </el-col>
        <el-col :span="12" style="margin-top:20px;">
          <el-form-item label="支付凭证">
            <uploadImg
              ref="uploadImg"
              :disabled="$route.name == 'runWaterManageInfo'"
              :file-num="fileNum"
              :file-list="fileList"
            />
          </el-form-item>
        </el-col>
        <!-- 支付信息 -->
      </el-row>
      <!-- 支付信息 -->
      <div class="divBar" />
      <h5 class="titleInfo">支付明细</h5>
      <el-form ref="list" :inline="true" :model="list" label-width="130px">
        <el-row>
          <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="payType" align="center" label="支付方式">
              <template slot-scope="scope">
                <div>
                  <span v-if="scope.row.payType == 1">信用卡快捷支付</span>
                  <span v-if="scope.row.payType == 2">借记卡快捷支付</span>
                  <span v-if="scope.row.payType == 3">微信支付</span>
                  <span v-if="scope.row.payType == 4">支付宝支付</span>
                  <span v-if="scope.row.payType == 5">退款</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="tradeNo" align="center" label="交易单号" />
            <el-table-column prop="amount" align="center" label="支付金额" />
            <el-table-column prop="payTime" align="center" label="支付时间" />
          </el-table>
        </el-row>
        <el-form-item>
          <el-button
            v-if="$route.name != 'runWaterManageInfo'"
            style="margin-top:30px;margin-left:130px"
            type="primary"
            @click="submitFn('form')"
          >立即提交</el-button>
        </el-form-item>
      </el-form>
    </el-form>
    <el-form v-else ref="list" :inline="true" :model="list" label-width="130px">
      <el-row>
        <el-col :span="12" v-if="list.paymentId == 3">
          <el-form-item label="支付状态">
            <span v-if="list.payStatus == 1">未支付</span>
            <span v-if="list.payStatus == 2">部分支付</span>
            <span v-if="list.payStatus == 3">全部支付</span>
          </el-form-item>
        </el-col>

        <el-col :span="12" v-if="list.paymentId == 3">
          <el-form-item label="已支付金额">{{ list.payPrice }}</el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="消费总金额">
            <el-input
              v-model="list.totalPrice"
              :disabled="$route.name == 'runWaterManageInfo'"
              @blur="needfun"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="扣除杂费金额">
            <el-input
              v-model="list.allPrice"
              :disabled="$route.name == 'runWaterManageInfo'"
              @blur="needfun"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="杂费金额">{{ idatas.toFixed(2) }}</el-form-item>
        </el-col>
        <el-col :span="24">
          <p
            style="margin: 0;color: #999;font-size: 10px;margin-top: -20px;margin-left: 130px"
          >扣除杂费金额修改有流水记录，其他金额修改没有</p>
        </el-col>
        <el-col :span="12" v-if="list.paymentId == 3">
          <el-form-item label="医院子商户余额">{{ avlBal }}</el-form-item>
        </el-col>
        <el-col :span="12" v-if="list.paymentId == 3">
          <el-form-item label="医院需扣款金额">{{ needprice }}</el-form-item>
        </el-col>
        <!-- <el-col :span="12">
          <el-form-item label="现金补贴">
            <el-input v-model="list.cashAllowance"></el-input>
          </el-form-item>
        </el-col>-->
        <!-- <el-col :span="12">
          <el-form-item label="积分补贴">
            <el-input v-model="list.integralAllowance"></el-input>
          </el-form-item>
        </el-col>-->
        <el-col :span="12">
          <el-form-item label="备注">
            <el-input :disabled="$route.name == 'runWaterManageInfo'" v-model="list.userRemark" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="支付凭证">
            <uploadImg
              ref="uploadImg"
              :disabled="$route.name == 'runWaterManageInfo'"
              :file-num="fileNum"
              :file-list="fileList"
            />
          </el-form-item>
        </el-col>
        <!-- 支付信息 -->
      </el-row>
      <!-- 支付信息 -->
      <div class="divBar" />
      <h5 class="titleInfo">支付明细</h5>
      <el-form ref="list" :inline="true" :model="list" label-width="130px">
        <el-row>
          <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="username" align="center" label="支付方式">
              <template slot-scope="scope">
                <div>
                  <span v-if="scope.row.payType == 1">信用卡快捷支付</span>
                  <span v-if="scope.row.payType == 2">借记卡快捷支付</span>
                  <span v-if="scope.row.payType == 3">微信支付</span>
                  <span v-if="scope.row.payType == 4">支付宝支付</span>
                  <span v-if="scope.row.payType == 5">退款</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="tradeNo" align="center" label="交易单号" />
            <el-table-column prop="amount" align="center" label="支付金额" />
            <el-table-column prop="payTime" align="center" label="支付时间" />
          </el-table>
        </el-row>
      </el-form>
      <el-row>
        <el-col :span="24">
          <el-form-item>
            <el-button
              v-if="$route.name != 'runWaterManageInfo'"
              style="margin-top:30px;margin-left:130px"
              type="primary"
              @click="submitFn('form')"
            >立即提交</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import uploadImg from "@/components/UploadImg/index";
import { policy, getPayedOrderList } from "@/api/policy";
import {
  getBeautyProjectOrderById,
  updateBeautyProjectOrder,
  updateBeautyProjectOrderljk,
  getWithdraw,
  getHospitalRefundAmount
} from "@/api/runWaterManage";
export default {
  name: "RunWaterManageEdit",
  filters: {
    filterNull(e) {
      if (!e) {
        return "暂无";
      } else {
        return e;
      }
    },
    imgFilter(e) {
      return localStorage.getItem("imgUrlPrefix") + e;
    },
    cardNull(e) {
      return window.helper.cardType(e);
    },
    userFocus(e) {
      return window.helper.userFocus(e);
    }
  },
  components: { uploadImg },
  data() {
    return {
      nozfMoney: 0,
      nozfMoneyStatus: "",
      newobj: {},
      ischeck: 0,
      istype: 0,
      loadings: true,
      limidata: 0,
      idatas: 0,
      avlBal: 0,
      needprice: 0,
      fileNum: 3,
      userId: "",
      fileList: [],
      list: {},
      oldList: {},
      form: {},
      tableData: [],
      rowData: [],
      flowList: {}
    };
  },
  mounted() {
    console.log();
    this.userId = String(this.$route.query.userId);
    this.getList();
    this.getinfo();
  },
  methods: {
    abc(row) {
      console.log(row);
      if (row.payType == 1) {
        row.zlzMoney = row.jlPayAccounts - 0 + (row.jlUnpaidAccounts - 0);
        row.xfzMoney = row.payMoney - 0 + (row.unpaidAccounts - 0);

        this.nozfMoneyStatus = false;
        if (this.nozfMoney < row.xfzMoney - row.zlzMoney) {
          this.nozfMoneyStatus = true;
        }
        console.log(this.nozfMoneyStatus);
      }
      if (row.payType == 4) {
        row.zlzMoney = row.xfzMoney;
      }
      row.zfMoney = row.xfzMoney - row.zlzMoney;
    },
    refundfun(row, payType) {
      console.log(row);
      this.ischeck = row;
      this.istype = payType;
    },
    /** */
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        // console.log(column, index, column.property);

        if (column.label.indexOf("操作") > -1) {
          sums[index] = ``;
          return;
        }
        if (index === 0) {
          sums[index] = "总价";
          return;
        }

        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += " 元";
        } else {
          sums[index] = "0";
        }
      });

      return sums;
    },

    async needfun() {
      if (this.list.totalPrice - this.list.allPrice < 0) {
        // this.$message.error("消费总金额不能小于扣除杂费金额");
        return;
      }
      if (this.list.totalPrice - this.list.allPrice > this.limidata) {
        //  this.$message.error("杂费金额不允许调高，请重新输入");
        return;
      } else {
        this.idatas =
          this.list.totalPrice - this.list.allPrice - this.list.goldCoin;
      }
      const res = await getHospitalRefundAmount({
        id: this.$route.query.userId,
        allPrice: this.list.allPrice + "",
        totalPrice: this.list.totalPrice + ""
      });
      console.log(res);
      if (res.data.code == 0) this.needprice = res.data.data;
    },
    async getWithdraw(id) {
      const res = await getWithdraw({ id: id + "" });

      if (res.data.code == 0) this.avlBal = res.data.data.avlBal;
    },
    getinfo() {
      getPayedOrderList({ id: this.$route.query.sn }).then(res => {
        console.log(res);
        if (res.data.code == 0) {
          this.tableData = res.data.data.list;
        }
      });
    },
    getList() {
      const datas = { id: this.userId };
      getBeautyProjectOrderById(datas)
        .then(res => {
          if (res.data.code == 0) {
            this.list = res.data.data;

            this.oldList = { ...res.data.data };
            this.flowList.totalPriceLimit = res.data.data.totalPriceLimit;
            this.flowList.allPriceLimit = res.data.data.allPriceLimit;
            //  this.flowList = [...this.oldList.flowList];
            this.oldList.flowList.map(res => {
              if (res.payType == 3) {
                this.flowList.jlStageMoney = res.zlzMoney;
                this.flowList.stageMoney = res.xfzMoney;
              }
              //金币
              if (res.payType == 4) {
                this.flowList.goldCoin = res.xfzMoney;
              }
              // 分期奖励金额

              // 分期金额
              if (res.payType == 1) {
                this.nozfMoney = res.xfzMoney - res.zlzMoney;
                this.flowList.unpaidAccounts = res.unpaidAccounts;
                // 未支付总金额
                this.flowList.jlUnpaidAccounts = res.jlUnpaidAccounts;
                // 现金奖励金额"
                this.flowList.payMoney = res.payMoney;

                // 支付总金额
                this.flowList.jlPayAccounts = res.jlPayAccounts;
                // 支付奖励金额
              }
              if (res.payType == 2) {
                this.flowList.ownMoney = res.xfzMoney;
                this.flowList.jlOwnMoney = res.zlzMoney;
              }

              // 现金金额
            });

            this.totalPricenumber = res.data.data.allPrice;
            this.limidata = this.list.totalPrice - this.list.allPrice;
            this.idatas =
              this.list.totalPrice - this.list.allPrice - this.list.goldCoin;
            this.getWithdraw(res.data.data.hospitalId);
            this.list.img.forEach(i => {
              this.fileList.push({
                url: localStorage.getItem("imgUrlPrefix") + i
              });
            });
          } else {
            this.$message.error(res.data.msg ? res.data.msg : "系统错误");
          }
          this.loadings = false;
        })
        .catch(error => {
          this.$message.error(error);
          this.loadings = false;
        });
    },
    // 提交
    submitFn() {
      console.log(this.list.paymentId != 4, 11111, this.list.paymentId);
      if (this.list.paymentId != 4) {
        console.log(2222);
        //老数据
        let tl = this.list;
        let to = this.oldList;
        // 扣除杂费金额
        // if (Number(tl.totalPrice) < Number(to.totalPriceLimit)) {
        //   this.$message.error("填写的消费总金额小于已报补贴单金额，请重新输入");
        //   return;
        // }
        if (this.list.paymentId == 3) {
          if (Number(tl.totalPrice) > Number(to.totalPrice)) {
            this.$message.error("消费总金额不允许调高，请重新输入");
            return;
          }
          if (
            Number(Number(tl.totalPrice) - Number(tl.allPrice)) >
            Number(Number(to.totalPrice) - Number(to.allPrice))
          ) {
            this.$message.error("杂费金额不能调高，请重新输入");
            return;
          }
          if (Number(tl.allPrice) > Number(to.allPrice)) {
            this.$message.error("扣除杂费金额不能调高，请重新输入");
            return;
          }
        }

        if (Number(tl.allPrice) < Number(to.allPriceLimit)) {
          this.$message.error("填写的流水单金额小于已报补贴单金额，请重新输入");
          return;
        }
        if (Number(tl.totalPrice) < Number(tl.allPrice)) {
          this.$message.error("消费总金额不能小于扣除杂费金额");
          return;
        }

        // old begin
        // if (this.list.totalPrice - this.list.allPrice < 0) {
        //     this.$message.error("消费总金额不能小于扣除杂费金额");
        //     return;
        // }
        // if (this.list.totalPrice - this.list.allPrice > this.limidata) {
        //     // this.$message.error("杂费金额不允许调高，请重新输入");
        //     this.$message.error("消费总金额不允许调高，请重新输入");
        //     return;
        // } else if (this.list.allPrice < this.list.allPriceLimit) {
        //     this.$message.error(
        //         "填写的流水单金额小于已报补贴单金额，请重新输入"
        //     );
        //     return false;
        // }
        // if (this.totalPricenumber < this.list.allPrice) {
        //     this.$message.error("扣除杂费金额不能调高");
        //     return;
        // }
        // old end

        const la = Number(this.list.allPrice);
        const lc = Number(this.list.cashAllowance); // 现金补贴
        const li = Number(this.list.integralAllowance); // 积分补贴
        //  if (false) {
        //  this.$message.error("扣除杂费金额与补贴金额不等");
        //   } else {
        // 判断图片是否上传成功
        const uploadList = this.$refs.uploadImg.submitUpload();
        if (uploadList != "uploadError") {
          this.form.img = uploadList;
          // 需要提交参数
          const newForm = [
            "allPrice",
            "totalPrice",
            "cashAllowance",
            "integralAllowance",
            "userRemark"
          ];
          newForm.forEach(i => {
            this.form[i] = this.list[i];
            this.form[i] = String(this.form[i]);
          });
          this.form["id"] = this.userId;
          // 类型转换参数
          const SZM = ["id", "integralAllowance"];
          SZM.forEach(i => {
            this.form[i] = Number(this.form[i]);
          });
          const datas = this.form;
          this.form.allPrice = parseFloat(this.list.allPrice).toFixed(2);
          this.form.totalPrice = parseFloat(this.list.totalPrice).toFixed(2);
          // console.log(datas)
          updateBeautyProjectOrderljk(datas)
            .then(res => {
              if (res.data.code == 0) {
                this.$message({
                  showClose: true,
                  message: "修改成功",
                  type: "success"
                });
                this.$router.push("/runWaterManageIndex");
              } else {
                this.$message.error(res.data.msg ? res.data.msg : "系统错误");
              }
            })
            .catch(error => {
              this.$message.error(error);
            });
        } else {
          this.$message.error("图片上传失败");
        }
        //  }
      } else {
        const tl = this.list;
        const to = this.oldList;
        const la = Number(this.list.allPrice);
        const lc = Number(this.list.cashAllowance); // 现金补贴
        const li = Number(this.list.integralAllowance); // 积分补贴
        //  if (false) {
        // this.$message.error("扣除杂费金额与补贴金额不等");
        // return false;
        // } else {
        // 判断图片是否上传成功
        const uploadList = this.$refs.uploadImg.submitUpload();

        const newobj = {};
        let xfzMoney = 0;
        let zlzMoney = 0;
        let flat = false;
        this.list.flowList.map(res => {
          xfzMoney += res.xfzMoney - 0;
          zlzMoney += res.zlzMoney - 0;
          if (res.zfMoney < 0) {
            flat = true;
          }
          if (res.payType == 4) {
            newobj.goldCoin = res.xfzMoney - 0;
          }
          if (res.payType == 3) {
            newobj.stageMoney = res.xfzMoney - 0;
            newobj.jlStageMoney = res.zlzMoney - 0;
          }
          if (res.payType == 1) {
            newobj.unpaidAccounts = res.unpaidAccounts - 0;
            // 未支付总金额
            newobj.jlUnpaidAccounts = res.jlUnpaidAccounts - 0;
            // 现金奖励金额"
            newobj.payMoney = res.payMoney - 0;

            // 支付总金额
            newobj.jlPayAccounts = res.jlPayAccounts - 0;
            // 支付奖励金额
          }
          if (res.payType == 2) {
            newobj.ownMoney = res.xfzMoney - 0;
            newobj.jlOwnMoney = res.zlzMoney - 0;
          }

          // 现金金额
        });
        console.log(this.flowList, newobj, zlzMoney, xfzMoney);
        /** 新的校验规则 */

        if (zlzMoney - newobj.jlUnpaidAccounts < this.flowList.allPriceLimit) {
          /**总奖励金额拦截判断 */
          console.log(zlzMoney, this.flowList.allPriceLimit);
          console.log(222222222222);
          this.$message.warning(
            `填写的流水单金额小于已报补贴单金额，请重新输入（限制为` +
              this.flowList.allPriceLimit +
              `）`
          );
          return 1;
        }

        if (this.nozfMoneyStatus) {
          this.$message.warning(`填写的线上的杂费不能调高，请重新输入`);
          return 1;
        }
        if (xfzMoney - newobj.unpaidAccounts < this.flowList.totalPriceLimit) {
          /**总金额拦截判断 */
          console.log(xfzMoney, this.flowList.totalPriceLimit);
          console.log(33333333333333);
          this.$message.warning(
            `填写的流水单金额小于已报补贴单金额，请重新输入（限制为` +
              this.flowList.totalPriceLimit +
              `）`
          );
          return 1;
        }
        if (flat) {
          this.$message.warning("杂费不能低于负数");
          return 1;
        }
        if (
          newobj.payMoney > this.flowList.payMoney ||
          newobj.payMoney < 0 ||
          newobj.jlPayAccounts > this.flowList.jlPayAccounts ||
          newobj.jlPayAccounts < 0
        ) {
          this.$message.warning("线上收款方式已支付金额不允许调高，请重新输入");
          return 1;
        }
        if (
          newobj.unpaidAccounts > this.flowList.unpaidAccounts ||
          newobj.unpaidAccounts < 0 ||
          newobj.jlUnpaidAccounts > this.flowList.jlUnpaidAccounts ||
          newobj.jlUnpaidAccounts < 0
        ) {
          this.$message.warning("线上收款方式未支付金额不允许调高，请重新输入");
          return 1;
        }
        if (
          newobj.ownMoney < 0 ||
          newobj.jlOwnMoney < 0 ||
          newobj.jlStageMoney < 0 ||
          newobj.stageMoney < 0
        ) {
          this.$message.warning("总金额金额,扣除杂费金额不能小于0，请重新输入");
          return 1;
        }
        //   if(){
        //   this.$message.warning('线上收款方式已支付金额不允许调高，请重新输入')
        // }
        if (uploadList != "uploadError") {
          this.form.img = uploadList;
          // 需要提交参数
          const newForm = [
            "allPrice",
            "totalPrice",
            "cashAllowance",
            "integralAllowance",
            "userRemark"
          ];
          newForm.forEach(i => {
            this.form[i] = this.list[i];
            this.form[i] = String(this.form[i]);
          });
          this.form["id"] = this.userId;
          // 类型转换参数
          const SZM = ["id", "integralAllowance"];
          SZM.forEach(i => {
            this.form[i] = Number(this.form[i]);
          });

          this.form.allPrice = parseFloat(this.list.allPrice).toFixed(2);
          this.form.totalPrice = parseFloat(this.list.totalPrice).toFixed(2);
          this.newobj = newobj;

          const datas = Object.assign(this.newobj, this.form);
          updateBeautyProjectOrder(datas)
            .then(res => {
              if (res.data.code == 0) {
                this.$message({
                  showClose: true,
                  message: "修改成功",
                  type: "success"
                });
                this.$router.push("/runWaterManageIndex");
              } else {
                this.$message.error(res.data.msg ? res.data.msg : "系统错误");
              }
            })
            .catch(error => {
              this.$message.error(error);
            });
        } else {
          this.$message.error("图片上传失败");
          return 1;
        }
      }
    },
    sure() {
      if (this.submitFn() !== 1) {
      }
    }
  }
};
</script>

<style scoped>
.app-container {
  padding: 0px !important;
}
.form {
  margin-left: 268px;
}
</style>
